package systemBeat;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class DataReader {

    private static List<Map<String, Object>> datas;

    public DataReader(String filePath,String sheetName){
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file(filePath), sheetName);
        DataReader.datas=reader.readAll();
    }

    public DataReader(File file, String sheetName){
        ExcelReader reader = ExcelUtil.getReader(file, sheetName);
        DataReader.datas=reader.readAll();
    }

    public List<Student> getAllStudents(){
        List<Student> results=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=datas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            Student student=new Student();
            student.setTestNumber((String) data.get(Const.testNumber));
            student.setGrade((Double) data.get(Const.grade));
            student.setKaochang((String) data.get(Const.kaochang));
            student.setName((String) data.get(Const.name));
            student.setSchoolNumber((String) data.get(Const.schoolNumber));
            student.setSiteNumber((String) data.get(Const.siteNumber));
        }
        return results;
    }
}
